package cn.ciis.basic.plugin;

import cn.ciis.basic.kit.CiisKit;
import cn.ciis.basic.model.Enterprise;
import cn.ciis.basic.model.Equipment;
import org.lionsoul.ip2region.DataBlock;
import org.tio.monitor.RateLimiterWrap;

import java.util.Optional;

public class CiisSessionContext {
    /**
     * 消息请求频率控制器
     */
    private RateLimiterWrap requestRateLimiter = null;

    /**
     * ip地址信息
     */
    private DataBlock dataBlock;

    /**
     * 企业信息
     */
    private Optional<Enterprise> enterprise=Optional.empty();

    /**
     * 设备信息
     */
    private Optional<Equipment> equipment=Optional.empty();

    /**
     * 是否是走了websocket协议
     */
    private boolean isWebsocket = false;

    public RateLimiterWrap getRequestRateLimiter() {
        return requestRateLimiter;
    }

    public void setRequestRateLimiter(RateLimiterWrap requestRateLimiter) {
        this.requestRateLimiter = requestRateLimiter;
    }

    public DataBlock getDataBlock() {
        return dataBlock;
    }

    public void setDataBlock(DataBlock dataBlock) {
        this.dataBlock = dataBlock;
    }

    public boolean isWebsocket() {
        return isWebsocket;
    }

    public void setWebsocket(boolean websocket) {
        isWebsocket = websocket;
    }

    public Optional<Enterprise> getEnterprise() {
        return enterprise;
    }

    public void setEnterprise(Enterprise enterprise) {
        this.enterprise = Optional.ofNullable(enterprise);
    }

    public Optional<Equipment> getEquipment() {
        return equipment;
    }

    public void setEquipment(Equipment equipment) {
        this.equipment = Optional.ofNullable(equipment);
    }

    public  String getBsId(){

        if(enterprise.isPresent() && equipment.isPresent()){
            return CiisKit.getTioBsId(enterprise.get(),equipment.get());
        }else{
            return null;
        }

    }
}
